package m202401.d10;

import m202401.d08.Q100;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/1/10 17:27
 */
//222. 完全二叉树的节点个数
public class Q222 {

    private int count = 0;

    public int countNodes(TreeNode root) {
        count = 0;
        doCount(root);
        return count;
    }

    public void doCount(TreeNode node) {
        if (node == null) {
            return;
        }
        count++;
        doCount(node.left);
        doCount(node.right);
    }

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
}
